using UnityEngine;
using System.Collections;

public class RunnerAlien : MonoBehaviour {
	
	GameObject player;
	int randomValue;
		
	// Use this for initialization
	void Start () 
	{
		randomValue = Random.Range(1,3);
		player = GameObject.FindGameObjectWithTag(("Player" + randomValue).ToString());
	}
	
	// Update is called once per frame
	void Update () 
	{
		transform.LookAt(new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z));
		transform.Translate(0,0,0.08f);
		animation.Play();
	}
	
	private void OnCollisionEnter(Collision other)
	{
		if(other.gameObject.tag == "Bullet")
		{
			Destroy(this.gameObject);
			Destroy(other.gameObject);
			SpawnAliens.numAliens--;
		}
	
		if(other.gameObject.tag == "Player1" || other.gameObject.tag == "Player2")
		{	
			Destroy(this.gameObject);
			SpawnAliens.numAliens--;
			
			PlayerRanged scriptPlayer;
			scriptPlayer = (PlayerRanged)other.gameObject.GetComponent("PlayerRanged");
			scriptPlayer.LostHP();
		}
	}
}
